package org.openmrs.propertyeditor;

import java.beans.PropertyEditorSupport;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.openmrs.ObligationContext;
import org.openmrs.UserObligation;
import org.openmrs.api.UserService;
import org.openmrs.api.context.Context;
import org.springframework.util.StringUtils;

public class UserObligationEditor extends PropertyEditorSupport {
	
	private Log log = LogFactory.getLog(this.getClass());
	
	public UserObligationEditor() {
		
	}
	
	public void setAsText(String text) throws IllegalArgumentException {
		Context.getUserService();
		if (StringUtils.hasText(text)) {
			//			try {
			//				UserObligation r = es.getUserObligation(text, text);
			//				setValue(r);
			//				if (r == null)
			//					throw new Exception();
			//			}
			//			catch (Exception ex) {
			//
			//			}
		} else {
			setValue(null);
		}
	}
	
	public String getAsText() {
		UserObligation obligation = (UserObligation) getValue();
		if (obligation == null)
			return "";
		else
			return obligation.getValue();
	}
	
}
